package com.ruoyi.web.controller.info;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.info.domain.VinfoCompany;
import com.ruoyi.info.service.IVinfoCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业信息Controller
 *
 * @author oy
 * @date 2022-12-16
 */
@RestController
@RequestMapping("/info/company")
public class VinfoCompanyController extends BaseController
{
    @Resource
    private IVinfoCompanyService vinfoCompanyService;

    /**
     * 查询企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(VinfoCompany vinfoCompany)
    {
        startPage();
        long userId = SecurityUtils.getUserId();
        List<VinfoCompany> list = vinfoCompanyService.selectVinfoCompanyList(vinfoCompany,userId);
        return getDataTable(list);
    }

    /**
     * 导出企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:company:export')")
    @Log(title = "企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VinfoCompany vinfoCompany)
    {
        long userId = SecurityUtils.getUserId();
        List<VinfoCompany> list = vinfoCompanyService.selectVinfoCompanyList(vinfoCompany,userId);
        ExcelUtil<VinfoCompany> util = new ExcelUtil<>(VinfoCompany.class);
        util.exportExcel(response, list, "企业信息数据");
    }

    /**
     * 获取企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:company:query')")
    @GetMapping(value = "/{compId}")
    public AjaxResult getInfo(@PathVariable("compId") Long compId)
    {
        return success(vinfoCompanyService.selectVinfoCompanyByCompId(compId));
    }

    /**
     * 新增企业信息
     */
    @PreAuthorize("@ss.hasPermi('info:company:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VinfoCompany vinfoCompany)
    {
        return toAjax(vinfoCompanyService.insertVinfoCompany(vinfoCompany));
    }

    /**
     * 修改企业信息
     */
    @PreAuthorize("@ss.hasPermi('info:company:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VinfoCompany vinfoCompany)
    {
        return toAjax(vinfoCompanyService.updateVinfoCompany(vinfoCompany));
    }

    /**
     * 删除企业信息
     */
    @PreAuthorize("@ss.hasPermi('info:company:remove')")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
	@PutMapping("/{compIds}")
    public AjaxResult remove(@PathVariable Long[] compIds)
    {
        return toAjax(vinfoCompanyService.deleteVinfoCompanyByCompIds(compIds));
    }

    /**
     * 获取公司下拉框列表
     * @return
     */
    @PreAuthorize("@ss.hasAnyRoles('admin,common')")
    @GetMapping("/selectitem")
    public AjaxResult selectCompItems()
    {
        long userId = SecurityUtils.getUserId();
        return AjaxResult.success(vinfoCompanyService.selectCompItems(userId));
    }
}
